﻿// Decompiled with JetBrains decompiler
// Type: CreateMfgByCoordinates.CUiCreCreateMfgTCForm
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using DnProcessSimulateCommands.CreateWeldPoint;
using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Windows.Forms.Layout;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;


namespace CreateMfgByCoordinates;

public class CUiCreCreateMfgTCForm : TxForm
{
  private Container components;
  private TextBox m_mfgName;
  private Label m_pointLabel;
  private Button m_buttonOK;
  private Button m_buttonCancel;
  private Label m_partLabel;
  private TxObjEditBoxCtrl m_part;
  private Label m_mfgNameLabel;
  private TxFrameEditBoxCtrl m_frame;
  private Label lblWeldContainer;
  private Label lblWeldOperation;
  public TxObjEditBoxCtrl txebWeldContainer;
  public TxObjEditBoxCtrl txebWeldOperation;
  private CApCreDialogTCLogic _logic = new CApCreDialogTCLogic();

  public CUiCreCreateMfgTCForm() => this.InitializeComponent();

  private void InitializeComponent()
  {
    ComponentResourceManager componentResourceManager = new ComponentResourceManager(typeof (CUiCreCreateMfgTCForm));
    this.m_mfgName = new TextBox();
    this.m_mfgNameLabel = new Label();
    this.m_pointLabel = new Label();
    this.m_partLabel = new Label();
    this.m_buttonCancel = new Button();
    this.m_buttonOK = new Button();
    this.m_part = new TxObjEditBoxCtrl();
    this.m_frame = new TxFrameEditBoxCtrl();
    this.lblWeldContainer = new Label();
    this.lblWeldOperation = new Label();
    this.txebWeldContainer = new TxObjEditBoxCtrl();
    this.txebWeldOperation = new TxObjEditBoxCtrl();
    ((Control) this).SuspendLayout();
    componentResourceManager.ApplyResources((object) this.m_mfgName, "m_mfgName");
    this.m_mfgName.Name = "m_mfgName";
    this.m_mfgName.TextChanged += new EventHandler(this.EnableOrDisableAcceptButtons);
    componentResourceManager.ApplyResources((object) this.m_mfgNameLabel, "m_mfgNameLabel");
    this.m_mfgNameLabel.Name = "m_mfgNameLabel";
    componentResourceManager.ApplyResources((object) this.m_pointLabel, "m_pointLabel");
    this.m_pointLabel.Name = "m_pointLabel";
    componentResourceManager.ApplyResources((object) this.m_partLabel, "m_partLabel");
    this.m_partLabel.Name = "m_partLabel";
    this.m_buttonCancel.DialogResult = DialogResult.Cancel;
    componentResourceManager.ApplyResources((object) this.m_buttonCancel, "m_buttonCancel");
    this.m_buttonCancel.Name = "m_buttonCancel";
    this.m_buttonCancel.Click += new EventHandler(this.m_buttonCancel_Click);
    componentResourceManager.ApplyResources((object) this.m_buttonOK, "m_buttonOK");
    this.m_buttonOK.Name = "m_buttonOK";
    this.m_buttonOK.Click += new EventHandler(this.m_buttonOK_Click);
    this.m_part.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.m_part.ListenToPick = true;
    componentResourceManager.ApplyResources((object) this.m_part, "m_part");
    ((Control) this.m_part).Name = "m_part";
    this.m_part.Object = (ITxObject) null;
    this.m_part.PickAndClear = false;
    this.m_part.PickLevel = (TxPickLevel) 1;
    this.m_part.PickOnly = false;
    this.m_part.ReadOnly = false;
    this.m_part.ValidatorType = (TxValidatorType) 1;
    this.m_frame.EnableRelativeToWorkingFrameCoordinates = true;
    this.m_frame.ListenToPick = true;
    componentResourceManager.ApplyResources((object) this.m_frame, "m_frame");
    ((Control) this.m_frame).Name = "m_frame";
    this.m_frame.PickLevel = (TxPickLevel) 6;
    this.m_frame.ValidatorType = (TxValidatorType) 1;
    this.m_frame.VisualizePickedFrameInGraphicViewer = false;
    this.m_frame.ValidFrameSet += new TxFrameEditBoxCtrl_ValidFrameSetEventHandler(this.m_frame_ValidFrameSet);
    this.m_frame.Picked += new TxFrameEditBoxCtrl_PickedEventHandler(this.m_frame_Picked);
    componentResourceManager.ApplyResources((object) this.lblWeldContainer, "lblWeldContainer");
    this.lblWeldContainer.Name = "lblWeldContainer";
    componentResourceManager.ApplyResources((object) this.lblWeldOperation, "lblWeldOperation");
    this.lblWeldOperation.Name = "lblWeldOperation";
    this.txebWeldContainer.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.txebWeldContainer.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txebWeldContainer, "txebWeldContainer");
    ((Control) this.txebWeldContainer).Name = "txebWeldContainer";
    this.txebWeldContainer.Object = (ITxObject) null;
    this.txebWeldContainer.PickAndClear = false;
    this.txebWeldContainer.PickLevel = (TxPickLevel) 1;
    this.txebWeldContainer.PickOnly = false;
    this.txebWeldContainer.ReadOnly = false;
    this.txebWeldContainer.ValidatorType = (TxValidatorType) 0;
    this.txebWeldContainer.TypeInvalid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldContainer.TypeValid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldContainer.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldOperation.KeepFaceEmphasizedWhenControlIsNotFocused = true;
    this.txebWeldOperation.ListenToPick = false;
    componentResourceManager.ApplyResources((object) this.txebWeldOperation, "txebWeldOperation");
    ((Control) this.txebWeldOperation).Name = "txebWeldOperation";
    this.txebWeldOperation.Object = (ITxObject) null;
    this.txebWeldOperation.PickAndClear = false;
    this.txebWeldOperation.PickLevel = (TxPickLevel) 1;
    this.txebWeldOperation.PickOnly = false;
    this.txebWeldOperation.ReadOnly = false;
    this.txebWeldOperation.ValidatorType = (TxValidatorType) 0;
    this.txebWeldOperation.TypeInvalid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldOperation.TypeValid += new EventHandler(this.EnableOrDisableAcceptButtons);
    this.txebWeldOperation.Picked += new TxObjEditBoxCtrl_PickedEventHandler(this.EnableOrDisableAcceptButtons);
    ((Form) this).AcceptButton = (IButtonControl) this.m_buttonOK;
    componentResourceManager.ApplyResources((object) this, "$this");
    ((Form) this).CancelButton = (IButtonControl) this.m_buttonCancel;
    ((Control) this).Controls.Add((Control) this.txebWeldOperation);
    ((Control) this).Controls.Add((Control) this.txebWeldContainer);
    ((Control) this).Controls.Add((Control) this.lblWeldOperation);
    ((Control) this).Controls.Add((Control) this.lblWeldContainer);
    ((Control) this).Controls.Add((Control) this.m_frame);
    ((Control) this).Controls.Add((Control) this.m_mfgName);
    ((Control) this).Controls.Add((Control) this.m_part);
    ((Control) this).Controls.Add((Control) this.m_buttonOK);
    ((Control) this).Controls.Add((Control) this.m_buttonCancel);
    ((Control) this).Controls.Add((Control) this.m_partLabel);
    ((Control) this).Controls.Add((Control) this.m_pointLabel);
    ((Control) this).Controls.Add((Control) this.m_mfgNameLabel);
    ((Form) this).FormBorderStyle = FormBorderStyle.FixedDialog;
    ((Form) this).MaximizeBox = false;
    ((Form) this).MinimizeBox = false;
    ((Control) this).Name = nameof (CUiCreCreateMfgTCForm);
    ((Form) this).Closed += new EventHandler(this.CUiCreCreateMfgTCForm_Closed);
    ((Form) this).Load += new EventHandler(this.CUiCreCreateMfgTCForm_Load);
    ((Control) this).ResumeLayout(false);
    ((Control) this).PerformLayout();
  }

  protected virtual void Dispose(bool disposing)
  {
    if (disposing && this.components != null)
      this.components.Dispose();
    base.Dispose(disposing);
  }

  protected void LoadPreselectedObjectsIntoControls()
  {
    this.m_part.Object = this._logic.GetSelectedPart();
    if (this.txebWeldContainer.Enabled)
    {
      ITxObject selectedWeldContainer = this._logic.GetSelectedWeldContainer();
      if (selectedWeldContainer != null)
        this.txebWeldContainer.Object = selectedWeldContainer;
    }
    ITxObject selectedWeldOperation = this._logic.GetSelectedWeldOperation();
    if (selectedWeldOperation == null)
      return;
    this.txebWeldOperation.Object = selectedWeldOperation;
  }

  protected void FocusEmptyField()
  {
    Control[] controlArray = new Control[4]
    {
      (Control) this.txebWeldContainer,
      (Control) this.txebWeldOperation,
      (Control) this.m_frame,
      (Control) this.m_part
    };
    foreach (Control control in controlArray)
    {
      switch (control)
      {
        case TxObjEditBoxCtrl _:
          TxObjEditBoxCtrl txObjEditBoxCtrl = control as TxObjEditBoxCtrl;
          if (txObjEditBoxCtrl.Enabled && txObjEditBoxCtrl.Object == null)
          {
            txObjEditBoxCtrl.Focus();
            txObjEditBoxCtrl.Select();
            return;
          }
          break;
        case TxFrameEditBoxCtrl _:
          TxFrameEditBoxCtrl frameEditBoxCtrl = control as TxFrameEditBoxCtrl;
          if (TxTransformation.op_Equality(frameEditBoxCtrl.GetLocation(), (TxTransformation) null))
          {
            frameEditBoxCtrl.Focus();
            ((Control) frameEditBoxCtrl).Select();
            return;
          }
          break;
      }
    }
  }

  protected void SetPickProviders()
  {
    TxPickProvider[] pickProviders = CApCreateWpTCLogic.GetPickProviders();
    if (this.txebWeldContainer.Enabled)
    {
      this.txebWeldContainer.SetPickProviders(pickProviders);
      this.txebWeldContainer.ListenToPick = true;
    }
    this.txebWeldOperation.SetPickProviders(pickProviders);
    this.txebWeldOperation.ListenToPick = true;
  }

  protected void SetValidators()
  {
    this.m_part.SetValidator(this._logic.PartValidator);
    if (this.txebWeldContainer.Enabled)
      this.txebWeldContainer.SetValidator((ITxValidator) this._logic._CompositeWeldContainerValidator);
    this.txebWeldOperation.SetValidator((ITxValidator) this._logic._CompositeWeldOperationValidator);
  }

  protected void EnableOrDisableAcceptButtons(object sender, EventArgs e)
  {
    this.m_buttonOK.Enabled = this._logic.IsDataValid(this.m_mfgName.Text, this.txebWeldContainer.Object, this.txebWeldOperation.Object);
  }

  private void m_buttonCancel_Click(object sender, EventArgs e)
  {
    this._logic.Cancel();
    ((Form) this).Close();
  }

  private void m_buttonOK_Click(object sender, EventArgs e)
  {
    this._logic.Accept(this.m_mfgName.Text, this.m_frame.GetLocation(), this.m_part.Object, this.txebWeldContainer.Object, this.txebWeldOperation.Object);
    ((Form) this).DialogResult = DialogResult.Yes;
    ((Form) this).Close();
  }

  private void m_frame_Picked(object sender, TxFrameEditBoxCtrl_PickedEventArgs args)
  {
    if (!this._logic.IsPart(args.Object))
      return;
    this.m_part.Object = (ITxObject) (args.Object as ITxProcessModelObject);
  }

  private void m_frame_ValidFrameSet(object sender, TxFrameEditBoxCtrl_ValidFrameSetEventArgs args)
  {
    this._logic.SetTemporaryFrame(this.m_frame.GetLocation());
  }

  private void CUiCreCreateMfgTCForm_Load(object sender, EventArgs e)
  {
    if (this._logic.IsWeldPointPrivate)
      this.CutWeldContainerFromForm();
    this.SetPickProviders();
    this.SetValidators();
    this.LoadPreselectedObjectsIntoControls();
    this.m_mfgName.Text = CApCreateWpTCLogic.GetUniqueWPDisplayName();
    this.FocusEmptyField();
    this.EnableOrDisableAcceptButtons((object) null, (EventArgs) null);
  }

  private void CUiCreCreateMfgTCForm_Closed(object sender, EventArgs e)
  {
    this.m_frame.LoseFocus();
    this.m_part.LoseFocus();
  }

  protected void CutWeldContainerFromForm()
  {
    int num = ((Control) this.txebWeldContainer).Top - this.m_mfgName.Bottom;
    foreach (Control control in (ArrangedElementCollection) ((Control) this).Controls)
    {
      if (control.Top > ((Control) this.txebWeldContainer).Top)
        control.Top -= ((Control) this.txebWeldContainer).Height + num;
    }
    ((Control) this.txebWeldContainer).Visible = false;
    this.txebWeldContainer.Enabled = false;
    this.lblWeldContainer.Visible = false;
    ((Control) this).Height = ((Control) this).Height - (((Control) this.txebWeldContainer).Height + num);
  }
}
